using Commons.Geom;
using System;

namespace Commons.Models.Functions
{
	[Serializable]
	public class LinearFunction : AbstractFunction<double, double>
	{
		private double m;
		private double b;

		public LinearFunction(double m, double b, string variable)
			: base(variable)
		{
			this.m = m;
			this.b = b;
		}

		public LinearFunction(Index2 point1, Index2 point2, string variable)
			: base(variable)
		{
			this.m = (point1.y - point2.y) / (point1.x - point2.x);
			this.b = point1.y - m * point1.x;
		}

		public override double Eval(double x)
		{
			return m * x + b;
		}
	}
}

